﻿Public Class DRUGDOSEWUSE

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub DRUGDOSEWUSE_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        queryMasdrgdosewuseGrid()

        DesignForm(Me)
        DesignGrid(MASDRGDOSWUSEGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Public Sub queryMasdrgdosewuseGrid()
        Dim objSelectDataMasdrgdoswuse As New masdrgdoswuse
        objSelectDataMasdrgdoswuse.DFORMData(DFORMCmb)
        objSelectDataMasdrgdoswuse.USEIDData(USEIDCmb)
        Dim masdrgdoswuseData As DataTable
        masdrgdoswuseData = connect.GetTable(objSelectDataMasdrgdoswuse.selectMasdrgdoswuse_)
        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
        MASDRGDOSWUSEGrid.PrimaryGrid.DataSource = masdrgdoswuseData
    End Sub

    Private Sub MASDRGDOSWUSEGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASDRGDOSWUSEGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value
        DUIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสการจับคู่").Value()
        DFORMCmb.SelectedValue = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("DFORM").Value()
        USEIDCmb.SelectedValue = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("USEID").Value()
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            masdrgdoswuseStatusChk.Checked = True
        Else
            masdrgdoswuseStatusChk.Checked = False
        End If
    End Sub

    Private Sub addMasdrgdoswuse_Click(sender As Object, e As EventArgs) Handles addMasdrgdoswuse.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If DFORMCmb.Text.ToString.Length > 0 And USEIDCmb.Text.ToString.Length > 0 Then
                    Dim objInsertData As New masdrgdoswuse
                    objInsertData.DFORM_ = DFORMCmb.SelectedValue
                    objInsertData.USEID_ = USEIDCmb.SelectedValue
                    objInsertData.STATUS_ = masdrgdoswuseStatusChk.Checked
                    objInsertData.insertMasdrgdoswuseData()

                    Dim objSelectDataMasdrgdoswuse As New masdrgdoswuse
                    objSelectDataMasdrgdoswuse.DFORMData(DFORMCmb)
                    objSelectDataMasdrgdoswuse.USEIDData(USEIDCmb)
                    Dim masdrgdoswuseData As DataTable
                    masdrgdoswuseData = connect.GetTable(objSelectDataMasdrgdoswuse.selectMasdrgdoswuse_)
                    'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                    MASDRGDOSWUSEGrid.PrimaryGrid.DataSource = masdrgdoswuseData
                    'Call MASDRGDOSWUSEGridFormat()

                    masdrgdoswuseStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasdrgdoswuse_Click(sender As Object, e As EventArgs) Handles editMasdrgdoswuse.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If DFORMCmb.Text.ToString.Length > 0 And USEIDCmb.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลการใช้ยาดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New masdrgdoswuse
                        objEditData.DUID_ = DUIDTxt.Text
                        objEditData.DFORM_ = DFORMCmb.SelectedValue
                        objEditData.USEID_ = USEIDCmb.SelectedValue
                        objEditData.STATUS_ = masdrgdoswuseStatusChk.Checked
                        objEditData.editMasdrgdoswuseData()

                        Dim objSelectDataMasdrgdoswuse As New masdrgdoswuse
                        objSelectDataMasdrgdoswuse.DFORMData(DFORMCmb)
                        objSelectDataMasdrgdoswuse.USEIDData(USEIDCmb)
                        Dim masdrgdoswuseData As DataTable
                        masdrgdoswuseData = connect.GetTable(objSelectDataMasdrgdoswuse.selectMasdrgdoswuse_)
                        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                        MASDRGDOSWUSEGrid.PrimaryGrid.DataSource = masdrgdoswuseData
                        'Call MASDRGDOSWUSEGridFormat()

                        masdrgdoswuseStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masdrgdosewuse")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masdrgdosewuse")
        nextform.ShowDialog()
    End Sub
End Class